package com.xianggu.designMode.strategy;

import java.util.HashMap;
import java.util.Map;

// 单例策略工厂
public class PaymentStrategyFactory {
    private static final Map<String, PaymentStrategy> strategies = new HashMap<>();

    static {
        strategies.put("alipay", new AlipayStrategy());
        strategies.put("wechat", new WechatPayStrategy());
        strategies.put("bankcard", new BankCardStrategy());
    }

    // 获取策略对象（单例）
    public static PaymentStrategy getStrategy(String type) {
        if (!strategies.containsKey(type)) {
            throw new IllegalArgumentException("不支持的支付类型：" + type);
        }
        return strategies.get(type);
    }
}